//
//  HomeTableViewController.swift
//  01-WeiBo
//
//  Created by 李晓东 on 17/6/24.
//  Copyright © 2017年 PeanutXu. All rights reserved.
//

import UIKit
let cellIdentifier = "CellIdentifier"
class HomeTableViewController: VistorTableViewController {

    private lazy var listViewModel = StatusListModel()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        print(view.frame.width)
        vistorView?.setupInfo(imageName: nil, tipText: "home")
        
        listViewModel.loadStatus { (isSuccessed) -> (Void) in
            guard isSuccessed else {
                print("some thing wrong")
                return
            }
            self.tableView.reloadData()
            
        }
        prepareTableView()
//        loadData()
    }
    
    func prepareTableView()  {
        tableView.register(StatusCell.self, forCellReuseIdentifier: cellIdentifier)
        tableView.estimatedRowHeight = 400
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
       return self.listViewModel.listModel.count
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! StatusCell
        cell.statusModel = listViewModel.listModel[indexPath.row]
        return cell
    }
    
//    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
//        return 80
//    }

}

extension HomeTableViewController{
    func loadData() {
        tableView.reloadData()
    }
}
